package org.wanho.shop.servlet;

import org.wanho.shop.entity.Product;
import org.wanho.shop.service.ProductService;
import org.wanho.shop.service.impl.ProductServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2023-04-26 11:20
 * Description：<描述>
 */
@WebServlet("*.product")
public class ProductServlet extends HttpServlet {

    private ProductService productService = new ProductServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String path = req.getServletPath();
        if("/findAll.product".equals(path)){
            findAll(req,resp);
        }
    }

    private void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Product> products = productService.findAll();
        req.setAttribute("products",products);
        req.getRequestDispatcher("/jsp/main.jsp").forward(req,resp);
    }
}
